找传奇、传世资源到传世资源站!

android 后台定时任务 示例源码下载

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

public class LongRunningService extends Service { @Nullable @Override public IBinder onBind(Intent intent) { return null; } public int onStartCommand(Intent intent,int flags,int startId){ new Thread(new Runnable() { @Override public void run() { Log.d("LongRunningService","executed at " new Date().toString()); //此部分就可以填写需要执行的具体功能代码,将耗时操作写于此处。效果是每隔一小时执行一次 //you can fill in this section you need to perform the specific function of the code, // write lengthy operations in here. The effect is, every hour will perform this function once. } }).start(); AlarmManager manager = (AlarmManager)getSystemService(ALARM_SERVICE); int anHour = 60*60*1000; long triggerAtTime = SystemClock.elapsedRealtime() anHour; Intent i= new Intent(this,AlarmReceiver.class); PendingIntent pi=PendingIntent.getBroadcast(this,0,i,0); manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,triggerAtTime,pi); return super.onStartCommand(intent,flags,startId); }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复